package com.ruipengkj.model;

import java.awt.Color;
import java.awt.Component;
import java.util.List;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class ColorTableCellRenderer extends DefaultTableCellRenderer {

	private static final long serialVersionUID = 1L;
	private List<Integer> redList, greedList;
	public ColorTableCellRenderer(List<Integer> redList, List<Integer> greedList) {
		this.redList = redList;
//		System.out.println(redList.size() + "   " + redList.get(0));
		this.greedList = greedList;
//		System.out.println(greedList.size() + "   " + greedList.get(0));
	}
	
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
		boolean isSelect = false;
		for(int i = redList.size() - 1; i >= 0; --i) {
			if (redList.get(i) == row) {
				this.setBackground(Color.red);
				isSelect = true;
			}
		}
		if (!isSelect)
		for(int i = greedList.size() - 1; i >= 0; --i) {
			if (greedList.get(i) == row) {
				this.setBackground(Color.green);
				isSelect = true;
			}
		}
		if (!isSelect)
			this.setBackground(Color.white);
		return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	}
}
